package com.briup.exception;

import com.briup.util.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 当程序中所有web层中代码发生异常，进行统一处理
 */
@ControllerAdvice// bean对象
public class TesthandleException {
    public TesthandleException(){
        System.out.println("创建TesthandleException对象");
    }
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result handleException(Exception e){
        System.out.println("全局异常处理代码....");
        return new Result(10001,e.getMessage());
    }
}
